package com.tarena.lbs.basic.web.repository;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.tarena.lbs.basic.web.mapper.AreaMapper;
import com.tarena.lbs.pojo.basic.bo.AreaBO;
import com.tarena.lbs.pojo.basic.dos.AreaDO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
public class AreaRepository {
    @Autowired
    private AreaMapper areaMapper;

    public List<AreaBO> queryAreaList(Long parentId) {
        List<AreaDO> areaDOS = areaMapper.selectProvinces(parentId);
        if (CollectionUtils.isNotEmpty(areaDOS)){
            List<AreaBO> areaBOS = areaDOS.stream().map(areaDO -> {
                AreaBO areaBO = new AreaBO();
                BeanUtils.copyProperties(areaDO,areaBO);
                return areaBO;
            }).collect(Collectors.toList());
            return areaBOS;
        }
        return null;
    }
}
